package com.ruoyi.gp.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gp.domain.vo.ShoppingPlatformVo;
import com.ruoyi.gp.domain.bo.ShoppingPlatformBo;
import com.ruoyi.gp.service.IShoppingPlatformService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购物平台
 *
 * @author ruoyi
 * @date 2024-03-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/ShoppingPlatform")
public class ShoppingPlatformController extends BaseController {

    private final IShoppingPlatformService iShoppingPlatformService;


    /**
     * 查询购物平台列表
     */
    @SaCheckPermission("system:ShoppingPlatform:list")
    @GetMapping("/list")
    public TableDataInfo<ShoppingPlatformVo> list(ShoppingPlatformBo bo, PageQuery pageQuery) {
        return iShoppingPlatformService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出购物平台列表
     */
    @SaCheckPermission("system:ShoppingPlatform:export")
    @Log(title = "购物平台", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ShoppingPlatformBo bo, HttpServletResponse response) {
        List<ShoppingPlatformVo> list = iShoppingPlatformService.queryList(bo);
        ExcelUtil.exportExcel(list, "购物平台", ShoppingPlatformVo.class, response);
    }

    /**
     * 获取购物平台详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:ShoppingPlatform:query")
    @GetMapping("/{id}")
    public R<ShoppingPlatformVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iShoppingPlatformService.queryById(id));
    }

    /**
     * 新增购物平台
     */
    @SaCheckPermission("system:ShoppingPlatform:add")
    @Log(title = "购物平台", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ShoppingPlatformBo bo) {
        return toAjax(iShoppingPlatformService.insertByBo(bo));
    }

    /**
     * 修改购物平台
     */
    @SaCheckPermission("system:ShoppingPlatform:edit")
    @Log(title = "购物平台", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ShoppingPlatformBo bo) {
        return toAjax(iShoppingPlatformService.updateByBo(bo));
    }

    /**
     * 删除购物平台
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:ShoppingPlatform:remove")
    @Log(title = "购物平台", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iShoppingPlatformService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

}
